home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Memphis Amiga Group / MAG Disk (1990-09)(Memphis Amiga Group).zip / MAG Disk (1990-09)(Memphis Amiga Group).adf / sMOVIE / source / sMOVIEtext.c < prev   
C/C++ Source or Header  |  1989-12-29  |  5KB  |  145 lines

  1. /* sMOVIEtext.c   - function to smooth scroll text up through a view.
  2.                     M. J. Round.     7 - Oct - 1989.                    */
  3.  
  4.  
  5. /*  This does NOT scroll by moving huge chunks of memory about.
  6.     What happens is like this..... (are you sitting comfortably?)....
  7.     
  8.     1.  We have a bitmap that is higher than what you can see on screen
  9.         - actually just over twice as high.  To start with, you can only see
  10.         the top part of the bitmap on your screen.
  11.         
  12.     2.  The text is written to the part of the bitmap which is off the
  13.         bottom of the screen (where you can't see it) and then the bitmap
  14.         is scrolled up to bring the new text into view.  This happens one
  15.         line of text at a time (one line for each call to this function).
  16.         Note that NO memory has to be moved to do the scroll - we just
  17.         ask the co-processor to display a different chunk of bitmap on the
  18.         screen. (Thanks Amiga!).
  19.         
  20.     3.  Unfortunately we don't have an infinitely big bitmap so comes the
  21.         time when we have to swap back to showing the top part of the 
  22.         bitmap... (This is the clever bit).....
  23.         
  24.     4.  As we write text to the part of the bitmap which is off the bottom
  25.         of the currently display, we also COPY it to the part of the
  26.         bitmap which is off the TOP of the current display.  When we get
  27.         near to the bottom of the bitmap, there is already a perfect copy
  28.         of the current screen up near the top of the bitmap - so we switch
  29.         that into view and start all over. (phew!)
  30.         
  31.     5.  There is no number 5.
  32.     
  33.     I'm sure there must be easier ways of doing this - I can think of at
  34.     least four - but this seemed elegant to me.
  35. */
  36.  
  37.  
  38. #include "sMOVIE.h"
  39.  
  40. extern int maxfontheight,abort_prog;
  41.  
  42. extern int mousemonitor(void);
  43.  
  44. extern int maxwidth;
  45.  
  46. extern int delay;            /*    delay between each pixel scroll */
  47.  
  48. extern int ypos;            /*    y posn of previous text base    */
  49.  
  50. extern struct View v;        /*    view to be smooth scrolled        */
  51.  
  52. extern struct RastPort rp;    /*    rastport to write text to        */
  53.  
  54. void smoothtext (text,length,xpos,apen,bpen,f)
  55.  
  56. char *text;             /* the text to be printed                        */
  57. short length;            /* length of text (in chars NOT pixels)         */
  58. short xpos;             /* x position to start text (in pixels)         */
  59. BYTE apen;              /* foreground (ink colour) pen                  */
  60. BYTE bpen;              /* background (paper colour) pen                */
  61. struct TextFont *f;     /* the font in use (open it elsewhere)          */
  62.  
  63. {    /*  NOTE: This always works as if JAM2 mode were selected    */
  64.  
  65.     int j,ysize,baseline,underhang,jump,hipos,chunk;
  66.  
  67.     register int i;
  68.     
  69.     WORD *ryoffset;
  70.     
  71.     ysize = f->tf_YSize;
  72.     ryoffset = &(v.ViewPort->RasInfo->RyOffset);
  73.  
  74.     for(i=0; i < ysize; i++) {    /*  each pass scrolls one pixel    */
  75.         switch(i) {
  76.  
  77.             case 1:
  78.                 /*    jump to top of bitmap if necessary    */
  79.                 underhang = ysize - (baseline = f->tf_Baseline);
  80.                 ypos += baseline;
  81.                 jump = v.ViewPort->DHeight + maxfontheight;
  82.                 if (ypos >= (rp.BitMap->Rows - underhang)) {
  83.                     ypos -= jump;
  84.                     *ryoffset -= jump;
  85.                     }
  86.                 SetAPen(&rp,bpen);
  87.                 SetOPen(&rp,bpen);
  88.                 SetDrMd(&rp,JAM1);
  89.                 SetFont(&rp,f);          /* select desired font      */
  90.                 hipos = ypos - jump;
  91.                 chunk = length >> 2;
  92.                 if (!abort_prog) abort_prog = mousemonitor();
  93.                 break;
  94.  
  95.             case 2:
  96.                 /*  clear line to background colour - ready for text    */
  97.                 RectFill(&rp,0,ypos-baseline,maxwidth-1,ypos+underhang);
  98.                 Move(&rp,xpos,ypos);     /* position ready to write  */
  99.                 SetAPen(&rp,apen);
  100.                 if (!abort_prog) abort_prog = mousemonitor();
  101.                 break;
  102.  
  103.             case 3:                     /* done like this 'cos "Text"    */
  104.             case 4:                     /* is too slow to manage a      */
  105.             case 5:                     /* whole line in 1/60 sec.      */
  106.                 Text(&rp,text,chunk);
  107.                 text += chunk;
  108.                 length -= chunk;
  109.                 break;
  110.  
  111.             case 6:
  112.                 Text(&rp,text,length);    /* print text in four chunks    */
  113.                 break;
  114.  
  115.             case 7:
  116.                  /*  copy the text up to the top part of the bitmap...
  117.                     ....(sometimes we don't need to...)                 */
  118.                 if((hipos >= baseline) && (*ryoffset >= (hipos + underhang)))
  119.                     ClipBlit(&rp,0,ypos-baseline         /* source posn  */
  120.                             ,&rp,0,hipos-baseline        /* dest posn    */
  121.                             ,maxwidth,ysize                /* size         */
  122.                             ,0xc0                        /* direct copy  */
  123.                             );
  124.                 else if (!abort_prog) abort_prog = mousemonitor();
  125.                 break;
  126.  
  127.             default :
  128.                 if (!abort_prog) abort_prog = mousemonitor();
  129.                 break;
  130.             }            /* end of switch    */
  131.  
  132.         ++(*ryoffset);
  133.         MakeVPort(&v, v.ViewPort);
  134.         MrgCop(&v);
  135.         
  136.         for (j=0; j<delay; j++)
  137.             WaitTOF();
  138.  
  139.         LoadView(&v);            /* scroll up one pixel              */
  140.         }                        /* repeat (height of font) times    */
  141.  
  142.     ypos += underhang;
  143.  
  144. }    /*  end of sMOVIEtext    */
  145.